package com.xugongzhang.volatileDemo;

import java.util.concurrent.TimeUnit;

/**
 * @author X
 * @date 2022/7/20 1:01
 */
public class VolatileTest {
    public static void main(String[] args) {
        MyMun myMun = new MyMun();
        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                for (int i1 = 0; i1 < 1000; i1++) {
                    myMun.addPP();
                }
            }, i + "").start();
        }
        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(myMun.flag);
    }
}

class MyMun {
    volatile int flag;

    public void addPP() {
        flag++;
    }
}
